export const setLocal = (key: string, value: any) => {
    localStorage.setItem(key, JSON.stringify(value))
}

export const getLocal = (key: string) => {
    const jsonValue = localStorage.getItem(key)

    if (jsonValue === 'undefined') {
        return {}
    } else if (jsonValue === null) {
        return ''
    } else {
        return JSON.parse(jsonValue || '{}')
    }
}

/**
 *
 * @param key string[] 数组就代表批量删除
 */
export const removeLocal = (key: string[]) => {
    key.forEach((item: string) => {
        localStorage.removeItem(item)
    })
}

export const clearLocal = () => {
    localStorage.clear()
}
